<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>AES加解密工具</title>
    <style>
        :root {
            --primary-color: #4a90e2;
            --danger-color: #ff4757;
            --success-color: #2ed573;
            --bg-color: #f5f6fa;
            --border-color: #dcdde1;
        }

        body {
            margin: 0;
            padding: 20px;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background-color: var(--bg-color);
            min-height: 100vh;
        }

        .container {
            display: flex;
            flex-direction: column;
            height: 95vh;
            gap: 15px;
            max-width: 1200px;
            margin: 0 auto;
        }

        .code-area-container {
            position: relative;
            flex: 1;
            min-height: 200px; /* 添加最小高度 */
            margin: 5px 0; /* 增加间隔 */
        }

        .code-area {
            position: absolute;
            top: 30px; /* 给工具栏留出空间 */
            bottom: 0;
            left: 0;
            right: 0;
            padding: 10px;
        }


        .code-area:focus {
            outline: none;
        }

        .control-bar {
            display: flex;
            align-items: center;
            gap: 15px;
            padding: 15px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .key-input {
            flex: 1;
            padding: 10px 15px;
            border: 2px solid var(--border-color);
            border-radius: 6px;
            font-size: 14px;
        }

        .btn {
            padding: 10px 25px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.2s;
        }

        .btn-encrypt {
            background: var(--primary-color);
            color: white;
        }

        .btn-decrypt {
            background: var(--success-color);
            color: white;
        }

        .btn:hover {
            opacity: 0.9;
        }

        .toolbar {
            position: absolute;
            top: 5px;
            right: 5px;
            z-index: 2; /* 确保在文本区域上方 */
        }

        .format-btn {
            padding: 5px 10px;
            background: rgba(255, 255, 255, 0.9);
            border: 1px solid var(--border-color);
            border-radius: 4px;
            cursor: pointer;
            display: flex;
            align-items: center;
            font-size: 12px;
        }

        .format-btn:hover {
            background: var(--primary-color);
            color: white;
        }

        .json-status {
            position: absolute;
            bottom: 5px;
            right: 5px;
            font-size: 11px;
            color: #666;
            background: rgba(255, 255, 255, 0.9);
            padding: 2px 6px;
            border-radius: 4px;
        }

        #errorMessage {
            color: var(--danger-color);
            font-size: 12px;
            height: 18px;
            text-align: center;
        }
    </style>
</head>
<body>
<div class="container">
    <!-- 明文区域 -->
    <div class="code-area-container">
        <div class="toolbar">
            <button class="format-btn" onclick="formatJSON('plaintext')">格式化 JSON</button>
        </div>
        <label for="plaintext"></label><textarea
            id="plaintext"
            class="code-area"
            placeholder="输入明文..."
            spellcheck="false"
    ></textarea>
    </div>

    <!-- 控制栏 -->
    <div class="control-bar">
        <button class="btn btn-encrypt" onclick="handleEncrypt()">加密 ↓</button>
        <label for="key"></label><input
            type="password"
            id="key"
            class="key-input"
            placeholder="输入AES密钥（16/24/32字节）"
            spellcheck="false"
    >
        <button class="btn btn-decrypt" onclick="handleDecrypt()">解密 ↑</button>
    </div>

    <!-- 密文区域 -->
    <div class="code-area-container">
        <label for="ciphertext"></label><textarea
            id="ciphertext"
            class="code-area"
            placeholder="输入HEX密文..."
            spellcheck="false"
    ></textarea>
    </div>

    <div id="errorMessage"></div>
</div>

<script src="./renderer.js"></script>
</body>
</html>
